/**
 * @file SendMessageHandler.cs
 * @author Zane Mayo
 * @date 13/5/2009
 */

using System;

namespace MxitAPI {
	
	
	public class SendMessageHandler : Handler {
		
		private static log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
		
		private int contactId;
		private MessageType messageType;
		private string messageText;
		private string flags;
		
		public SendMessageHandler() : base( typeof( SendMessageProtocolMessage ) )  {
			
		}
		
		public SendMessageHandler( int contactId, MessageType messageType, string messageText, string flags ) : this() {
			
			this.contactId = contactId;
			this.messageType = messageType;
			this.messageText = messageText;
			
			// Todo fix the flags
			if ( flags != "" )
				this.flags = flags;
			else
				this.flags = "512";
			
			log.Debug( "SendMessageHandler created" );
		}
		
		
		public override ProtocolMessage CreateRequestProtocolMessage() {
			
			SendMessageProtocolMessage sendMessage = new SendMessageProtocolMessage();
			sendMessage.ContactAddress = Contacts.Instance.GetContact( contactId ).ContactAddress;
			sendMessage.MessageType = messageType;
			sendMessage.MessageText = messageText;
			sendMessage.Flags = flags;
			
			log.Debug( "SendMessageProtocolMessage created" );
			
			return sendMessage;
		}

		
	}
}
